package com.cold.legendary.bprocess.common.constance;

import lombok.Getter;

/**
 * @author cold
 * @since 2023/3/8
 */
public enum BErrorCodeEnum {

    SUCCESS("BP0000", "成功"),
    ERROR("BP9999", "错误"),

    //业务异常
    BIZ_ERROR("BP0001", "业务异常"),

    //BP1000 - BP1999 db层异常定义
    DB_PARAMS_ERROR("BP1000", "Repository层入参异常"),
    DB_OPERATOR_ERROR("BP1001", "数据库操作失败"),

    //BP2000 - BP2999 框架级异常定义
    SYS_CONTEXT_ERROR("BP2000", "ProcessContextApplicationListener执行的时候找不到spring上下文！"),
    SYS_NO_BPOINT_ERROR("BP2001", "检测到带有@BPoint注解的bean,未实现BPointService接口!请实现!"),
    SYS_NO_BPROCESS_ERROR("BP2002", "检测到带有@BProcess注解的bean,未实现BProcessDefinition接口!请实现!"),
    SYS_BPROCESS_NO_BPOINT_ERROR("BP2003", "检测到process无定义的业务节点,请检查流程定义@BProcess的类!"),
    SYS_BPROCESS_NONE_BPOINT_ERROR("BP2004", "检测到process定义中,PointId为空!请检查流程定义@BProcess的类!"),
    SYS_BPROCESS_BPOINT_NO_IMPL_ERROR("BP2005", "检测到process定义中的PointId无合法的@BPoint注解实现类!请实现或者流程定义中去掉此PointId!"),
    SYS_BUILD_ERROR("BP2006", "构建出流程链引用为空!"),
    SYS_NO_SEQUENCE_ERROR("BP2007", "使用loan-process框架,请务必实现配套sequence逻辑类!检测到无@BSequence注解的实现类!"),
    SYS_NOT_STRING_ERROR("BP2008", "检测到@BSequence注解的实现方法返回值类型不为java.lang.String!请检查返回值!"),
    SYS_NO_SEQUENCE_IMPL_ERROR("BP2009", "检测到无@BSequence注解的实现方法,请实现之!"),
    SYS_NO_PROCESSINS_IMPL_ERROR("BP2010", "流程实例不存在!"),
    SYS_CREATE_SERIAL_ERROR("BP2011", "序号产生异常!"),
    SYS_POINTID_NONE_ERROR("BP2012", "pointId不能为空!"),
    SYS_PROCESS_REQUEST_NONE_ERROR("BP2013", "流程请求记录不存在!"),
    SYS_TRIGGERBPOINTINS_NONE_ERROR("BP2014", "triggerBPointIns不能为空!"),
    SYS_POINT_NOT_MATCH_ERROR("BP2015", "节点不匹配,不允许流转!"),
    SYS_CAN_NOT_CONTINUE_ERROR("BP2016", "此节点非等待中状态!无法触发continue!"),
    SYS_RUN_PROCESS_REQUEST_NONE_ERROR("BP2016", "运行过程,流程请求记录不存在!"),
    SYS_RETRY_MISS_PARAMS_ERROR("BP2017", "缺失必要参数,无法记录重试数据,无法进行节点自动重试!"),
    SYS_ONLY_ERROR_POINT_ERROR("BP2018", "此节点非错误状态!无法触发execute!"),


    ;

    @Getter
    private String code;
    @Getter
    private String msg;

    BErrorCodeEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static BErrorCodeEnum of(String code) {
        for (BErrorCodeEnum em : BErrorCodeEnum.values()) {
            if (em.getCode().equals(code)) {
                return em;
            }
        }
        return null;
    }

}
